package cn.iocoder.yudao.module.api.product.spu.enums;

import cn.iocoder.yudao.framework.business.basic.enums.EnumValuable;
import cn.iocoder.yudao.framework.business.basic.enums.SortTypeEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 排序字段枚举
 *
 * @author 山野羡民
 */
@Getter
@AllArgsConstructor
public enum ProductSpuSortFieldEnum implements EnumValuable {

    DEFAULT(0, "综合排序"),
    PRICE(1, "价格排序"),
    SALES_COUNT(2, "销量排序"),
    CREATE_TIME(3, "时间排序"),
    RANDOM(4, "随机排序"),
    ;

    @EnumValue
    private final Integer value;
    private final String name;

    public static SortTypeEnum toSortType(Integer value) {
        if (value == null) {
            return SortTypeEnum.UNKNOWN;
        }
        if (PRICE.getValue().equals(value)) {
            return SortTypeEnum.PRICE;
        }
        if (SALES_COUNT.getValue().equals(value)) {
            return SortTypeEnum.SALES_COUNT;
        }
        if (CREATE_TIME.getValue().equals(value)) {
            return SortTypeEnum.ID;
        }
        if (RANDOM.getValue().equals(value)) {
            return SortTypeEnum.RANDOM;
        }
        return SortTypeEnum.UNKNOWN;
    }

}
